package com.woniuxy.house.mapper;

import com.woniuxy.house.entity.Search;
import com.woniuxy.house.provider.SearchSqlProvider;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

/**
 * 查询记录接口
 * @author baobo
 * @date 2022-08-28-12:37
 */
public interface SearchMapper {
	/**
	 * 新增查询记录
	 * @param search
	 */
	@Insert("insert into house_search(time,content,user_id) values(#{time},#{content},#{user.id})")
	void add(Search search);

	/**
	 * 通过id物理删除历史记录
	 * @param id
	 */
	@Delete("delete from house_search where id=#{id}")
	void delete(Integer id);

	/**
	 * 多条件查询搜索记录
	 * @param search
	 * @return
	 */
	@SelectProvider(value = SearchSqlProvider.class,method = "getByCondition")
	List<Search> getByCondition(Search search);

	/**
	 * 根据传入的number 查询出查询数量最多的搜索记录
	 * @param number
	 * @return
	 */
	@Select("SELECT COUNT(*) counts,content FROM house_search GROUP BY content ORDER BY counts DESC LIMIT #{number}  ")
	List<Search> getHottestSearch(Integer number);
	/**
	 * 通过用户ID查询搜索记录
	 * */
	@Select("select * from house_search where user_id=#{id}")
	List<Search> getByUserId(Integer userId);
}
